<?php
namespace app\home\controller;
use think\Db;
use think\captcha\Captcha;
use think\Loader;
class Product extends \think\Controller{
    public function product(){
        $id=$_GET['id'];
        $reslist=db('admin_addshop')->where('id',$id)->select();

        $data=array();
        foreach($reslist as $val){
            $img=json_decode($val['img'],true);
            if($img!=NULL){
                $val['img']=$img;
            }
            $data[]=$val;
        }

        $sku_id=db('goods_format_sku')->where('goods_id',$id)->column('sku');
        $sku_ids=implode(',',$sku_id);
        $sku_ids=str_replace('_',',',$sku_ids);
        $formatInfo=db('goods_format_value')->alias('a')->join('goods_format_name b',' a.format_id=b.id ')
        ->field('a.*,b.name')->where("a.id IN({$sku_ids})")->select();
        $formatData=[];
        foreach($formatInfo as $val){
            $formatData["{$val['name']}"][]=$val;
        }

        $format_vals=db('goods_format_sku')->where('goods_id',$id)->select();
        $formatSkuData=[];
        foreach($format_vals as $val){
            $formatSkuData["{$val['sku']}"]=$val;
        }
        
        $this->assign('reslist',$data);
        $this->assign('formatData',$formatData);
        $this->assign('formatSkuData',json_encode($formatSkuData));

        return $this->fetch('product');//继承基类的控制器 
    }
   
    
}